package com.qxzn.app.util;

import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.support.annotation.ColorInt;
import android.text.TextUtils;

public class DrawableUtil {

    public static GradientDrawable getShapeDrawable(@ColorInt int color, float radius) {
        return getShapeDrawable(color, radius, GradientDrawable.RECTANGLE);
    }

    public static GradientDrawable getShapeDrawableWithBorder(@ColorInt int color, int borderWidth, int borderColor, float radius) {
        GradientDrawable drawable = getShapeDrawable(color, radius, GradientDrawable.RECTANGLE);
        drawable.setStroke(borderWidth, borderColor);
        return drawable;
    }

    public static GradientDrawable getShapeDrawable(@ColorInt int color, float radius, int shape) {
        GradientDrawable drawable = new GradientDrawable();
        drawable.setColor(color);
        drawable.setCornerRadius(radius);
        drawable.setShape(shape);
        return drawable;
    }

    public static GradientDrawable getCircleShapeDrawable(@ColorInt int color) {
        GradientDrawable drawable = new GradientDrawable();
        drawable.setColor(color);
        drawable.setShape(GradientDrawable.OVAL);
        return drawable;
    }

    /**
     * 获取图片名称获取图片的资源id的方法
     *
     * @param context
     * @param imageName
     * @return
     */
    public static int getImgResource(Context context, String imageName) {
        if (TextUtils.isEmpty(imageName)) {
            return context.getResources().getIdentifier("logo", "mipmap", context.getPackageName());
        }
        return context.getResources().getIdentifier(imageName, "mipmap", context.getPackageName());
    }

}
